/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nanosn.coffeemaker.application.commands.generate.util;

import com.nanosn.coffeemaker.Project;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author selkhateeb
 */
public class Helper {

    public static Map<String, Object> getVariables(String applicationName) throws Exception {
        ArrayList<Map<String, Object>> entityClasses =
                new ArrayList<Map<String, Object>>();
        for (Class<?> clazz : Project.getClassLoader().getModelClasses()) {
            entityClasses.add(new EntityClass(clazz).getAsMap());
        }



        HashMap<String, Object> variables = new HashMap<String, Object>();
        String dir = Project.getSettings().getRootPackage() + "." +
                     applicationName;
        variables.put("Entities", entityClasses);
        variables.put("classNames", getClassNames());
        variables.put("applicationName", applicationName);
        variables.put("directory", dir.replace(".", "/"));
        variables.put("rootPackage", Project.getSettings().getRootPackage());

        return variables;
    }

    private static ClassName[] getClassNames() throws Exception {

        Class[] classes = Project.getClassLoader().getModelClasses();

        ArrayList<ClassName> stringClasses = new ArrayList<ClassName>();

        for (Class class1 : classes) {
            stringClasses.add(new ClassName(class1.getSimpleName()));
        }

        return stringClasses.toArray(new ClassName[stringClasses.size()]);
    }
}
